
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;


/**
 *
 * @author William
 */
public class EchoClient 
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException
    {
        Socket echoSocket = null;
        
        PrintWriter out = null;
        BufferedReader in = null;
        
        final String SERVER_IP = "192.168.0.128";
        
        try
        {
            echoSocket = new Socket(SERVER_IP,33333);
            out = new PrintWriter(echoSocket.getOutputStream(),true);
            in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
        }
        catch(UnknownHostException uhe)
        {
            System.err.println("Cannot find server");
            System.exit(1);
        }
        
        Scanner scan = new Scanner(System.in);
        
        String userInput;
        String serverMessage;
        
        do
        {
            System.out.println("Enter a message for the server((Bye to exit): ");
            userInput = scan.nextLine();
            out.println(userInput);
            
            serverMessage = in.readLine();
            System.out.println("The server says: " + serverMessage);
        }while(!userInput.equalsIgnoreCase("BYE"));
        
        in.close();
        out.close();
        scan.close();
        echoSocket.close();
                
        
        
    }
}
